package com.sskj.hangqing.ui.fragment;


import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.ImageView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.flyco.tablayout.SlidingTabLayout;
import com.sskj.common.adapter.MyFragmentPagerAdapter;
import com.sskj.common.base.App;
import com.sskj.common.util.ImageUtil;
import com.sskj.hangqing.R;
import com.sskj.hangqing.R2;
import com.sskj.hangqing.http.HttpConfig;
import com.sskj.hangqing.presenter.ZixunFragmentPresenter;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

@Route(path = RConfig.APP_FRAGMENT_ZIXUN)
public class ZixunFragment extends BaseFragment<ZixunFragmentPresenter> {
    @BindView(R2.id.slidingTabLayout)
    SlidingTabLayout slidingTabLayout;
    @BindView(R2.id.viewPager)
    ViewPager viewPager;
    @BindView(R2.id.ivBanner)
    ImageView ivBanner;
    String[] titles = new String[]{App.INSTANCE.getString(R.string.hang_zixunFragment1)};


    @Override
    protected int getLayoutId() {
        return R.layout.app_fragment_zixun;
    }

    @Override
    public ZixunFragmentPresenter getPresenter() {
        return new ZixunFragmentPresenter();
    }

    @Override
    public void initView() {

        ArrayList<Fragment> fragments = new ArrayList<>();
        fragments.add((Fragment) ARouter.getInstance().build(RConfig.APP_FRAGMENT_ZIXUN_LIST).navigation());
//        fragments.add((Fragment) ARouter.getInstance().build(RConfig.APP_FRAGMENT_GUIDE_LIST).navigation());
        viewPager.setAdapter(new MyFragmentPagerAdapter(getChildFragmentManager(), fragments));
        slidingTabLayout.setViewPager(viewPager, titles);
    }

    @Override
    public void initData() {
        mPresenter.getBanner();
    }

    public void updateUI(List<String> data) {
        if (data == null || data.isEmpty() || ivBanner == null)
            return;
        ImageUtil.setOriginImage(HttpConfig.BASE_IMG_URL + data.get(0), ivBanner);
    }
}
